<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: gaofang
 * @Date: 2020-11-23 18:29:13
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-02-10 11:12:42
-->
<template>
  <a-card>
    <p style="font-size: 18px; text-align: center">其他入库单</p>
    <br />
    <!-- 单据 -->
    <a-form-model ref="ruleForm" :model="Form" v-bind="layout" :rules="rules"
      ><!-- 顶部的信息 -->
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号" ref="document" prop="document">
            <a-input
              style="border: 0"
              v-model="Form.document"
              disabled
            ></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="单据日期"
            ref="documentDate"
            prop="documentDate"
          >
            <a-date-picker
              v-model="Form.documentDate"
              type="date"
              placeholder="请选择时间"
              style="width: 100%"
              @change="onChange"
            />
          </a-form-model-item>
        </a-col>

        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <a-select
              v-model="Form.depotName"
              showSearch
              style="width: 100%"
              @change="setdataSourceDepartment"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="
                  item.depotNo + '|' + item.depotName + '|' + item.depotId
                "
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="所属单位">
            <a-select
              v-model="Form.storageUnitName"
              showSearch
              style="width: 100%"
              @change="setdataSourcestorageUnit"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="
                  item.depotNo + '|' + item.depotName + '|' + item.depotId
                "
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col> -->

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="部门" ref="deptIdName" prop="deptIdName">
            <a-tree-select
              v-model="Form.deptIdName"
              show-search
              style="width: 100%"
              :tree-data="depTree"
              allow-clear
              @change="onChangeBumen"
            ></a-tree-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="收发类别"
            ref="sendReceiveTypeName"
            prop="sendReceiveTypeName"
          >
            <a-select
              placeholder=""
              showSearch
              v-model="Form.sendReceiveTypeName"
              @change="shoufaleibieMethod"
            >
              <a-select-option
                v-for="(item, index) in shoufaleibieList"
                :key="index"
                :value="item.id + '|' + item.name"
                >{{ item.name }}
              </a-select-option>
            </a-select>
            <!-- <a-select
              v-model="Form.sendReceiveType"
              @change="getSendReceiveTypeId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in SendReceiveList"
                :key="item.value"
                :value="item.title"
              >
                {{ item.title }}
              </a-select-option>
            </a-select> -->
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库存组织" ref="bodyname" prop="bodyname">
            <a-select
              v-model="Form.bodyname"
              @change="getpk_calbodyId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in InventoryOrganizationList"
                :key="item.id"
                :value="item.pkCalbody + '|' + item.bodyname"
              >
                {{ item.bodyname }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="公司" ref="pkCorpName" prop="pkCorpName">
            <a-tree-select
              v-model="Form.pkCorpName"
              show-search
              style="width: 100%"
              allow-clear
              :tree-data="pk_corpList"
              @change="getpk_corpId"
            >
            </a-tree-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="库管员"
            ref="cwhsmanagerName"
            prop="cwhsmanagerName"
          >
            <a-select
              @change="getcwhsmanagerId"
              v-model="Form.cwhsmanagerName"
              showSearch
              style="width: 100%"
              @search="searchUserInfoList"
            >
              <a-select-option
                v-for="item in UserList"
                :key="item.userId"
                :value="item.workNo + '|' + item.userName + '|' + item.userId"
              >
                {{ item.workNo }} {{ item.userName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="业务员" ref="salesman" prop="salesman">
            <a-select
              @change="getsalesman"
              v-model="Form.salesmanName"
              showSearch
              style="width: 100%"
              @search="searchUserInfoList"
            >
              <a-select-option
                v-for="item in UserList"
                :key="item.userId"
                :value="item.workNo + '|' + item.userName + '|' + item.userId"
              >
                {{ item.workNo }} {{ item.userName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="出库仓库">
            <a-select
              v-model="Form.cotherwhName"
              showSearch
              style="width: 100%"
              @change="RuKuCangKuMethod"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="
                  item.depotNo + '|' + item.depotName + '|' + item.depotId
                "
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="供应商"
            ref="ccustomerName"
            prop="ccustomerName"
          >
            <a-select
              v-model="Form.ccustomerName"
              @change="getClientId"
              @search="getAllClientList"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in clientList"
                :key="item.id"
                :value="item.No + '|' + item.name + '|' + item.id"
              >
                {{ item.No }} {{ item.name }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="农户" ref="farmerName" prop="farmerName">
            <a-select
              v-model="Form.farmerName"
              @change="getfarmerId"
              @search="getAllfarmerList"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in farmerList"
                :key="item.id"
                :value="item.No + '|' + item.name + '|' + item.id"
              >
                {{ item.No }} {{ item.name }}
              </a-select-option>
            </a-select>
            <!-- <a-input
              v-model="Form.farmer"
              style="background-color: white; color: black"
              :auto-size="{ minRows: 2 }"
            /> -->
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="备注" ref="" prop="">
            <a-input
              v-model="Form.remark"
              style="background-color: white; color: black"
              :auto-size="{ minRows: 2 }"
            />
          </a-form-model-item>
        </a-col>
        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="在建项目"
            ref="projectsUnderConstruction_text"
            prop="projectsUnderConstruction_text"
          >
            <a-select
              v-model="Form.projectsUnderConstruction_text"
              @change="zaijianMethod(Form.projectsUnderConstruction_text)"
              style="width: 100%"
            >
              <a-select-option
                v-for="(item, index) in zaijianList"
                :key="index"
                :value="item.id + '|' + item.engineerName"
              >
                {{ item.engineerName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="用途" ref="" prop="">
            <a-textarea
              v-model="Form.useTo"
              style="background-color: white; color: black"
              :auto-size="{ minRows: 2 }"
            />
          </a-form-model-item>
        </a-col> -->
      </a-row>
    </a-form-model>

    <!-- 生成原单按钮组件 -->
    <andother
      :orderColumns="orderColumns"
      :listColumns="listColumns"
      :ModalTitle="ModalTitle"
      @origin-data="getOriginData"
    ></andother>

    <!-- //TODO: -->
    <!-- 单据对应表格 -->
    <a-table
      :columns="columns"
      :data-source="DataSource"
      style="margin-top: 10px"
      :pagination="false"
      :scroll="{ x: 4000, y: 670 }"
    >
      <!-- :scroll="{ x: 2500, y: 670 }" -->
      <!-- 仓库编码 -->
      <span slot="depotNo" slot-scope="text, record">
        <a-select
          v-model="record.depotNo"
          showSearch
          style="width: 100%"
          @change="setGoodsList(record.key)"
        >
          <a-select-option
            v-for="item in storageList"
            :key="item.depotNo"
            :value="item.depotNo + '|' + item.depotName + '|' + item.depotId"
          >
            {{ item.depotNo }} {{ item.depotName }}
          </a-select-option>
        </a-select>
      </span>
      <!-- 库位 -->
      <span slot="depotLocation" slot-scope="text, record">
        <a-tree-select
          v-model="record.depotLocation"
          style="width: 100%"
          :tree-data="record.positionList"
          allow-clear
        ></a-tree-select>
        <!-- <a-select v-model="record.depotLocation" style="width: 100%">
          <a-select-option
            v-for="item in positionList"
            :key="item.title"
            :value="item.value"
          >
            {{ item.title }}
          </a-select-option>
        </a-select> -->
      </span>
      <!-- 仓位 -->
      <span slot="position" slot-scope="text, record">
        <a-tree-select
          v-model="record.position"
          style="width: 100%"
          :tree-data="record.positionList"
          allow-clear
        ></a-tree-select>
        <!-- <a-select v-model="record.position" style="width: 100%">
          <a-select-option
            v-for="item in positionList"
            :key="item.title"
            :value="item.value"
          >
            {{ item.title }}
          </a-select-option>
        </a-select> -->
      </span>
      <!-- 所属单位 -->
      <!-- <span slot="storageUnit" slot-scope="text, record">
        <a-select
          v-model="record.storageUnitName"
          showSearch
          style="width: 100%"
          @change="getstorageUnitId($event, record)"
        >
          <a-select-option
            v-for="item in storageList"
            :key="item.depotNo"
            :value="item.depotNo + '|' + item.depotName + '|' + item.depotId"
          >
            {{ item.depotNo }} {{ item.depotName }}
          </a-select-option>
        </a-select>
      </span> -->

      <!-- 存货编名称-->
      <span slot="inventoryName" slot-scope="text, record">
        <a-select
          v-model="record.inventoryName"
          style="width: 100%"
          :default-active-first-option="false"
          :show-arrow="false"
          :filter-option="false"
          :not-found-content="null"
          @search="handleSearch"
          @change="getInventoryInfo(record)"
          showSearch
          :disabled="Waiting"
        >
          <a-select-option
            v-for="(item, index) in goodsList"
            :key="index"
            :value="
              item.inventoryId +
              '|' +
              item.inventoryNo +
              '|' +
              item.inventoryName +
              '|' +
              item.specificationsModel +
              '|' +
              item.unit
            "
          >
            {{ item.inventoryNo }} {{ item.inventoryName
            }}{{ item.specificationsModel }}
          </a-select-option>
        </a-select>
      </span>
      <!-- <span slot="inventoryNo" slot-scope="text, record">
        <a-select
          v-model="record.inventoryNo"
          style="width: 100%"
          @change="getInventoryInfo(record)"
          showSearch
        >
          <a-select-option
            v-for="item in record.goodsList"
            :key="item.inventoryId"
            :value="item.inventoryNo + '|' + item.inventoryName"
          >
            {{ item.inventoryNo }} {{ item.inventoryName }}
          </a-select-option>
        </a-select>
      </span> -->

      <!-- 辅助单位 -->
      <span slot="auxiliaryUnit" slot-scope="text, record">
        <a-select
          v-model="record.auxiliaryUnit"
          style="width: 100%"
          @change="disableUnit(record.key)"
          showSearch
        >
          <a-select-option
            v-for="item in Auxiliary_Unitlist"
            :key="item.value"
            :value="item.title + '|' + item.value"
          >
            {{ item.value }} {{ item.title }}
          </a-select-option>
        </a-select>
      </span>

      <!-- 数量 -->
      <span slot="quantity" slot-scope="text, record">
        <a-input-number v-model="record.quantity" :min="0" :precision="3" />
      </span>

      <!-- 批次号 -->
      <span slot="batchNumber" slot-scope="text, record">
        <a-select
          v-model="record.batchNumber"
          style="width: 100%"
          @change="getBalanceTemp(record)"
        >
          <a-select-option
            v-for="item in record.BatchList"
            :key="item"
            :value="item"
          >
            {{ item }}
          </a-select-option>
        </a-select>
      </span>
      <!-- 出库日期 -->
      <span slot="deliveryDate" slot-scope="text, record">
        <a-date-picker
          @change="formatDeliveryDate(record.key)"
          v-model="record.deliveryDate"
          type="date"
          placeholder="请选择时间"
          style="width: 100%"
        />
      </span>

      <!-- 用途 -->
      <span slot="useTo" slot-scope="text, record">
        <a-input v-model="record.useTo" />
      </span>
      <!-- 货架 -->
      <span slot="shelves" slot-scope="text, record">
        <a-select v-model="record.shelves" style="width: 100%" />
      </span>
      <!-- 备注 -->
      <span slot="remark" slot-scope="text, record">
        <a-input v-model="record.remark" />
      </span>
      <!-- 出菇领料金额 -->
      <!-- <span slot="amountOfFruitPicking" slot-scope="text, record">
        <a-input v-model="record.amountOfFruitPicking" />
      </span> -->

      <!-- 出库日期 -->
      <!-- <span slot="deliveryDate" slot-scope="text, record">
         <a-date-picker
              v-model="record.deliveryDate"
              type="date"
              placeholder="请选择时间"
              style="width: 100%"
              @change="(...event)=>{onChangeChuKuRiQi(event,record)}"
            />
      </span> -->

      <template slot="action" slot-scope="text, record">
        <!-- <span v-if="record.isNew"> -->
        <span>
          <a @click="getGoodsShelves(record.key)">选择货架</a>
        </span>
        <a-divider type="vertical" />
        <span>
          <a @click="cancle(record.key)">取消</a>
        </span>
        <!-- <span v-else>
          <a-popconfirm
            ok-text="确定"
            cancel-text="取消"
            @confirm="Delete(record.id)"
          >
            <template slot="title">
              <p>确定删除？</p>
            </template>
            <a type="danger"> 删除 </a>
          </a-popconfirm>
        </span> -->
      </template>
    </a-table>
    <a-button
      style="width: 100%; margin-top: 16px; margin-bottom: 8px"
      type="dashed"
      icon="plus"
      @click="newMember"
      >添加</a-button
    >

    <div style="margin-top: 20px">
      <!-- 单据 -->
      <a-form-model
        ref="ruleFormUnder"
        :model="Form"
        v-bind="layout"
        :rules="rules"
        ><!-- 顶部的信息 -->
        <a-row>
          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item
              label="负责人"
              ref="responsiblePerson"
              prop="responsiblePerson"
            >
              <a-select
                v-model="Form.responsiblePersonName"
                style="width: 100%"
                showSearch
                @change="setResponsible_person"
              >
                <a-select-option
                  v-for="item in responsiblePersonList"
                  :key="item.userId"
                  :value="item.workNo + '|' + item.userName + '|' + item.userId"
                >
                  {{ item.workNo }} {{ item.userName }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核人" ref="inspector" prop="inspector">
              <a-select
                v-model="Form.inspectorName"
                showSearch
                @change="setInspector"
                style="width: 100%"
              >
                <a-select-option
                  v-for="item in inspectorList"
                  :key="item.userId"
                  :value="item.userId + '|' + item.workNo + '|' + item.userName"
                >
                  {{ item.workNo }} {{ item.userName }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核日期">
              <a-date-picker
                v-model="Form.balance"
                type="date"
                style="width: 100%"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="制单人">
              <a-input disabled v-model="Form.singleProducerName"> </a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- 提交按钮组  
      1. 能审核提交的人是不能点击保存的
      2. 能保存的人是不能审核和提交的
      -->
      <div style="margin-top: 20px">
        <center>
          <!-- <a-button type="primary" style="margin-right: 20px"> 打印 </a-button> -->

          <a-button
            @click="Save"
            style="margin-right: 20px"
            :disabled="isAntiAudit"
          >
            保存
          </a-button>

          <a-button
            style="margin-right: 20px"
            :disabled="!isAntiAudit"
            @click="Auditfunction"
          >
            审核
          </a-button>

          <!-- <a-button style="margin-right: 20px" disabled> 提交 </a-button> -->
        </center>
      </div>

      <GoodsShelvesInfo
        :goodsShelvesTag="goodsShelvesTag"
        :tableKey="tableKey"
        :storageId="storageId"
        ref="goodShelvesInfo"
        @get-goodShelveInfo="getGoodShelveInfo"
        @close-goodShelveInfo="closegoodShelveInfo"
      ></GoodsShelvesInfo>
    </div>
  </a-card>
</template>

<script>
import GoodsShelvesInfo from "../../components/common/GoodsShelvesInfo"; //

// import generateInfo from "../../components/common/generateInfo";
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
// 1. 导入

import moment from "moment";
import { mapState, mapGetters } from "vuex";
// import andother from "../../components/common/andother";
// import { ZiDianBiaoHttp } from "@/services/modules/ZiDianBiao";
// const zidianbiao = new ZiDianBiaoHttp(); // 字典表
import { JiJianChuKuHttp } from "@/services/modules/ChuKuGuanLi/JJianChuKu/JiJianChuKu";
const JiJianChuKu = new JiJianChuKuHttp(); // 基建出库

// 物品信息表格
const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
  },
  {
    title: "仓库编码",
    key: "depotNo",
    dataIndex: "depotNo",
    width: 270,

    align: "center",
    scopedSlots: { customRender: "depotNo" },
  },
  {
    title: "仓库名称",
    key: "depotName",
    dataIndex: "depotName",
    align: "center",
    // scopedSlots: { customRender: "depotName" },
  },
  // {
  //   title: "库位",
  //   key: "depotLocation",
  //   dataIndex: "depotLocation",
  //   align: "center",
  //   scopedSlots: { customRender: "depotLocation" },
  // },
  {
    title: "仓位",
    key: "position",
    dataIndex: "position",
    align: "center",
    scopedSlots: { customRender: "position" },
  },
  // {
  //   title: "所属单位",
  //   key: "storageUnit",
  //   dataIndex: "storageUnit",
  //   width: 270,

  //   align: "center",
  //   scopedSlots: { customRender: "storageUnit" },
  // },

  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
  },
  {
    title: "存货名称",
    dataIndex: " ",
    key: "inventoryName",
    align: "center",
    width: 600,
    scopedSlots: { customRender: "inventoryName" },
  },
  {
    title: "规格型号",
    dataIndex: "standardModel",
    key: "standardModel",
    align: "center",
  },
  {
    title: "单位",
    key: "unit",
    dataIndex: "unit",
    align: "center",
  },
  {
    title: "辅助单位",
    key: "auxiliaryUnit",
    dataIndex: "auxiliaryUnit",
    align: "center",
    scopedSlots: { customRender: "auxiliaryUnit" },
  },
  {
    title: "现存数量",
    key: "balance",
    dataIndex: "balance",
    align: "center",
  },
  // {
  //   //! 接口中暂时没有该属性
  //   title: "应出数量",
  //   key: "quantity",
  //   dataIndex: "quantity",
  //   align: "center",
  //   scopedSlots: { customRender: "quantity" },
  // },
  {
    title: "实发数量",
    key: "quantity",
    dataIndex: "quantity",
    align: "center",
    scopedSlots: { customRender: "quantity" },
  },
  {
    title: "单价",
    key: "unitPrice",
    dataIndex: "unitPrice",
    align: "center",
    scopedSlots: { customRender: "unitPrice" },
  },
  {
    title: "金额",
    key: "money",
    dataIndex: "money",
    align: "center",
    scopedSlots: { customRender: "money" },
  },

  {
    title: "源单单号",
    key: "sourceNumber",
    dataIndex: "sourceNumber",
    width: 220,

    align: "center",
  },
  // {
  //   title: "批次号",
  //   key: "batchNumber",
  //   dataIndex: "batchNumber",
  //   align: "center",
  //   scopedSlots: { customRender: "batchNumber" },
  // },

  {
    title: "出库日期",
    key: "deliveryDate",
    dataIndex: "deliveryDate",
    align: "center",
    scopedSlots: { customRender: "deliveryDate" },
  },

  // {
  //   title: "用途",
  //   dataIndex: "useTo",
  //   key: "useTo",
  //   align: "center",
  //   scopedSlots: { customRender: "useTo" },
  // },

  //   {
  //     title: "出菇领料金额",
  //     dataIndex: "amountOfFruitPicking",
  //     key: "amountOfFruitPicking",

  //     align: "center",
  //     scopedSlots: { customRender: "amountOfFruitPicking" },
  //   },
  {
    title: "货架",
    dataIndex: "shelves",
    key: "shelves",
    align: "center",
    scopedSlots: { customRender: "shelves" },
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
    scopedSlots: { customRender: "remark" },
  },
  {
    title: "货架",
    dataIndex: "goodsShelves",
    key: "goodsShelves",
    align: "center",
  },
  {
    title: "操作",
    dataIndex: "action",
    key: "action",
    align: "center",
    fixed: "right",
    scopedSlots: { customRender: "action" },
  },
];

// 基建出库申请单生成基建出库单-上半部分
const orderColumns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
  },
  {
    title: "申请单号",
    dataIndex: "requisitionNo",
    key: "requisitionNo",
    align: "center",
  },
  {
    title: "申请日期",
    dataIndex: "applicationDate",
    key: "applicationDate",
    align: "center",
  },
  {
    title: "申请部门",
    dataIndex: "applicationDept_dictText",
    key: "applicationDept_dictText",
    align: "center",
  },
  {
    title: "申请人",
    dataIndex: "applicant_dictText",
    key: "applicant_dictText",
    align: "center",
  },
  // {
  //   title: "收发类别",
  //   dataIndex: "sendReceiveType_text",
  //   key: "sendReceiveType_text",
  //   align: "center",
  // },
  {
    title: "用途",
    dataIndex: "usageDescription",
    key: "usageDescription",
    align: "center",
  },
  {
    title: "单据状态",
    dataIndex: "action",
    key: "action",
    align: "center",
    fixed: "right",
    scopedSlots: { customRender: "action" },
  },
];

// 基建出库申请单生成基建出库单-下半部分
const listColumns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
  },
  // {
  //   title: "所属单位",
  //   dataIndex: "storageUnit_dictText",
  //   key: "storageUnit_dictText",
  //   align: "center",
  // },
  {
    title: "仓库编码",
    dataIndex: "depotNo",
    key: "depotNo",
    align: "center",
  },
  {
    title: "仓库名称",
    dataIndex: "depotId_dictText",
    key: "depotId_dictText",
    align: "center",
  },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
  },

  {
    title: "存货名称",
    dataIndex: "inventoryNo_dictText",
    key: "inventoryNo_dictText",
    align: "center",
    width: "15%",
  },
  {
    title: "规格型号",
    dataIndex: "standardModel",
    key: "standardModel",
    align: "center",
  },
  {
    title: "单位",
    dataIndex: "unit",
    key: "unit",
    align: "center",
  },

  {
    title: "数量",
    dataIndex: "actualQuantity",
    key: "actualQuantity",
    align: "center",
  },
  // {
  //   title: "备注",
  //   dataIndex: "remark",
  //   key: "remark",
  //   align: "center",
  // },
  {
    title: "单据状态",
    dataIndex: "action",
    key: "action",
    align: "center",
    fixed: "right",
    scopedSlots: { customRender: "action" },
  },
];

export default {
  components: {
    GoodsShelvesInfo,
  },
  computed: {
    // 获取本地数据
    ...mapState("user", { currUser: "info", currPost: "position" }),
    ...mapGetters({
      getDepsInfo: "user/getDepsInfo",
    }),
    // ...mapState("setting", ["isMobile"]),
  },
  data() {
    return {
      Waiting: false,
      // 子组件传参
      goodsShelvesTag: false,
      tableKey: 0,
      storageId: "",

      isAntiAudit: false,

      IsNotEmpty: true, //提交时是否否和全部必填条件，是返回true

      InventoryOrganizationList: [], // 库存组织列表
      UserList: [], // 库管员列表
      workNoList: [], // 判重使用
      pk_corpList: [], // 公司列表
      clientList: [], // 供应商列表
      farmerList: [], // 农户列表

      // IsNotEmpty: true, //是否清空的标志（在表格信息不完整时，进行提示，但是表格数据不会被清空。正常的处理时需要重置）
      // BatchList: [], // 批次列表

      //库存组织下拉框
      KuCunZuZhiList: [],

      // ----- 申请的表单内容信息 -----
      Form: {
        id: "", // id
        document: "", //! 单据号
        documentDate: moment().format("YYYY-MM-DD"), //! 单据日期
        balance: moment().format("YYYY-MM-DD"),
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", //! 仓库Id

        // storageUnit: "", //! 所属单位名称
        // storageUnitName: "", // 所属单位name
        storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号

        deptIdName: "", // 部门名称
        deptId: "", //! 部门id

        sendReceiveType: "", //! 收发类别名称 integer(int32)
        sendReceiveTypeName: "", // 收发类别name

        //与用友对接部分
        bodyname: "山东七河生物", //库存组织名称
        pkCalbody: "1001F3100000000002LS", //!库存组织名称id

        pkCorp: "1001", //!公司id,前端显示数据库名称
        pkCorpName: "山东七河生物科技股份有限公司", //公司name,前端显示数据库名称

        cwhsmanagerid: "", //!库管员id
        cwhsmanagerName: "", //库管员name
        cwhsmanagerNumb: "", //库管员手机号

        salesman: "", //!业务员id
        cbizid: "", //!业务员id 这里两个都传,传一样的
        salesmanName: "", //业务员name

        cotherwhid: "", //!入库仓库id
        cotherwhName: "", //入库仓库name

        ccustomerid: "", //! 供应商id
        // clientId: "", // 供应商id 这个不用了,用上面的       ccustomerName: "", //供应商name
        ccustomerName: "", //供应商name

        farmer: "", //! 农户id
        farmerName: "", //农户name

        remark: "", //!备注

        //表格下方的数据
        responsiblePerson: "", //! 负责人 (传userid)）
        responsiblePersonName: "", // 负责人name

        inspector: "", //! 审核人(传userid)
        inspectorName: "", // 审核人name

        singleProducerName: this.$store.state.user.info.username, // 制单人名称
        singleProducer: this.$store.state.user.info.id, // 制单人Id

        amountOfFruitPicking: "", //出菇领料金额
      },
      // 字典表等数据
      storageList: [], // 仓库列表
      depTree: [], // 部门列表
      shoufaleibieList: [], //收发类别列表
      // SendReceiveList: [], //收发类别列表

      // 库位列表
      positionList: [], // 仓位、库位
      Auxiliary_Unitlist: [], // 辅助单位列表
      batchNumberList: [], // 批次号列表

      responsiblePersonList: [], // 负责人列表
      inspectorList: [], // 审核人列表
      inspectorIdList: [], // 审核人Id列表
      // zaijianList: [], // 在建项目列表

      UpdateTmp: true, // 修改标志

      // 格式
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 15 },
      },
      // 规则
      rules: {
        document: [
          {
            required: true,
            message: "单据号不能为空！",
            trigger: "change",
          },
        ],
        document_date: [
          {
            required: true,
            message: "单据日期不能为空！",
            trigger: "change",
          },
        ],

        deptIdName: [
          {
            required: true,
            message: "部门不能为空！",
            trigger: "change",
          },
        ],
        sendReceiveTypeName: [
          {
            required: true,
            message: "收发类别不能为空！",
            trigger: "change",
          },
        ],

        responsiblePerson: [
          {
            required: true,
            message: "负责人不能为空！",
            trigger: "change",
          },
        ],
        inspector: [
          {
            required: true,
            message: "审核人不能为空！",
            trigger: "change",
          },
        ],
        // 库存组织
        bodyname: [
          {
            required: true,
            message: "库存组织不能为空！",
            trigger: "change",
          },
        ],
        // 公司
        pkCorpName: [
          {
            required: true,
            message: "公司不能为空！",
            trigger: "change",
          },
        ],
        // 库管员
        cwhsmanagerName: [
          {
            required: true,
            message: "库管员不能为空！",
            trigger: "change",
          },
        ],
      },

      // ------- 表格 --------
      // 列表
      columns,
      DataSource: [],
      goodsList: [],

      selectedRowKeys: [],

      // 往子组件传参数据
      orderColumns,
      listColumns,
      otherId: "", // 表一Id
      autoSize: {
        x: 4000,
        y: 670,
      },
      // ExamineDisplay: true, // 审核、提交按钮是否显示
    };
  },
  // 生命周期函数
  mounted() {
    this.getApplyStorage(); // 获取仓库
    this.judgeDocument(); //判断单据号是否为空
    this.getSyncInventoryOrganizationList();
    this.getZaiJianList(); //在建项目列表
    this.shoufaleibieListmethod(); //收发类别列表
    this.getResponsiblePersonList(); // 获取负责人列表
    this.getInspectorList(); // 获取审核人
    this.getApplyOrder(); // 获取单号
    // this.setColumns(); // 生成多条数据

    // this.getUserIdByRoleName(); // 通过角色名称查询人员信息
    this.getDeparmentTree(); // 部门树
    this.setDataSource(); // 生成多条数据
    // this.getSaleDepartmentList(); // 获取销售部门
    // 获取供应商
    // 获取收发类别

    // this.getPositionInformationList(); // 获取仓位列表
    this.getAuxiliary_Unitlist(); // 获取辅助单位列表
    // this.getGiveawayList(); // 是否赠品列表

    // this.getSendReceiveList(); //收发类别列表
    // this.getsource();
    this.getRouterParam(); // 获取路由跳转的时候的参数

    this.getSendReceiveList();
    this.getpk_corpList();
  },
  watch: {
    //————————————反审核结束————————————————————————————
    $route(to, from) {
      //监听路由是否变化
      console.log("to", to);
      let id = to.query.Id;
      console.log("from", from);
      console.log("this.$route.params.articleId", this.$route.params.articleId);
      this.setInitInfo(id);
    },
  },
  methods: {
    //————————————反审核开始————————————————————————————
    //! 反审核功能
    Auditfunction() {
      this.updateOrderAndGoodsData(); // 更新表单和物品数据

      this.addGoodsData(); // 新增物品数据

      this.$message.success("审核成功");
      //标志位修改
      this.postSynchronized("未同步");
      this.update_audit("未反审核");
      // this.update_Mark(1);

      // 跳转回列表页面
      this.$router.push("/OtherOutputList");
    },
    //! 是否同步标志位
    postSynchronized(isOrNo) {
      let data = {
        id: this.Form.id,
        isSynchronized: isOrNo,
      };
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res);
      });
    },
    //是否反审核标志位
    update_audit(isOrNo) {
      let data = {
        id: this.Form.id,
        isAntiAudit: isOrNo,
      };
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res);
      });
    },
    //审核标志位
    update_Mark(isOrNo) {
      let data = {
        id: this.form.id,
        auditMark: isOrNo,
      };
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res);
      });
    },
    // ————判断单据号是否为空————
    judgeDocument() {
      setTimeout(() => {
        if (this.Form.document === "") {
          this.$message.error("未获取到单据号,请刷新页面重试");
        }
      }, 3000);
    },
    // 获取货架信息
    getGoodsShelves(key) {
      this.goodsShelvesTag = true;
      this.tableKey = key;
      this.storageId = "1001F3100000000002O0";

      setTimeout(() => {
        this.$refs.goodShelvesInfo.getGoodShelveInfo();
      }, 1000);
      //
    },
    closegoodShelveInfo() {
      this.goodsShelvesTag = false;
    },

    // 关闭货架
    getGoodShelveInfo(key, goodsShelvesList) {
      console.log("序号和货架列表", key, goodsShelvesList);

      let str = "";
      goodsShelvesList.forEach((element) => {
        str = str + element.inOutShelf + ",";
      });

      str = str.substring(0, str.length - 1);

      this.$set(this.DataSource[key - 1], "goodsShelves", str);

      this.goodsShelvesTag = false;
    },

    //获取在建项目列表
    getZaiJianList() {
      JiJianChuKu.getZaiJian().then((res) => {
        console.log("在建项目", res);
        this.zaijianList = res.result;
      });
    },
    //在建项目触发函数
    zaijianMethod(value) {
      console.log("在建项目触发函数value", value);
      let array = value.split("|");
      this.Form.projectsUnderConstruction = array[2];
      this.Form.cprojectid = array[2];
      this.Form.projectsUnderConstruction_text = array[1];
      console.log("在建项目触发函数this.Form", this.Form);
    },

    // 农户列表
    getAllfarmerList(value) {
      if (value != "") {
        comHttp
          .queryByLikeName("?customerName=" + value + "&custflag=1,3")
          .then((res) => {
            console.log("农户列表", res);
            this.farmerList = [];
            for (let i = 0; i < res.result.list.length; i++) {
              let data = {
                No: res.result.list[i].custcode, //编号
                id: res.result.list[i].pkCumandoc,
                name: res.result.list[i].custname,
              };
              this.farmerList.push(data);
            }
          });
      }
    },
    // 供应商列表
    getAllClientList(value) {
      if (value != "") {
        comHttp
          .queryByLikeName("?customerName=" + value + "&custflag=1,3")
          .then((res) => {
            console.log("供应商列表", res);
            this.clientList = [];
            for (let i = 0; i < res.result.list.length; i++) {
              let data = {
                No: res.result.list[i].custcode, //编号
                id: res.result.list[i].pkCumandoc,
                name: res.result.list[i].custname,
              };
              this.clientList.push(data);
            }
            console.log("供应商列表", this.clientList);
          });
      }
    },
    // 获取农户列表
    getfarmerId(value) {
      console.log("value::::", value);
      let array = value.split("|");
      this.Form.farmerName = array[1];
      this.Form.farmer = array[2];
      console.log("this.Form.farmer", this.Form.farmer);
    },
    // 获取供应商列表
    getClientId(value) {
      console.log("供应商值::::", value);
      let array = value.split("|");
      this.Form.ccustomerid = array[2];
      this.Form.ccustomerName = array[1];
      console.log("this.Form.ccustomerid", this.Form.ccustomerid);
    },
    // 获取库存组织列表
    getSyncInventoryOrganizationList() {
      comHttp.getSyncInventoryOrganizationList().then((res) => {
        console.log("库存组织", res);
        this.InventoryOrganizationList = res.result;
      });
    },
    // 获取库存组织Id
    getpk_calbodyId(value) {
      console.log("value", value);
      let array = value.split("|");
      this.Form.pkCalbody = array[0];
      console.log("this.Form.pkCalbody", this.Form.pkCalbody);
    },

    // 获取公司
    getpk_corpList() {
      comHttp.getpk_corpList().then((res) => {
        console.log("公司", res);
        this.pk_corpList = res.result;

        this.changeCorpData(this.pk_corpList);

        console.log(123124, this.pk_corpList);
      });
    },
    // 改变用友传递过来的数据为组件能识别的数据
    changeCorpData(Tree) {
      Tree.forEach((element) => {
        element["title"] = element.unitcode + " " + element.unitname;
        element["value"] = element.pkCorp + "|" + element.unitname;
        element["children"] = element.syncCompanyEntityList;
        element["key"] = element.id;

        if (element.children) {
          this.changeCorpData(element.children);
        }
      });
    },

    // 获取公司Id
    getpk_corpId(value, label, extra) {
      console.log("11111111111111", value);
      console.log("2222222222", label);
      console.log("33333333333", extra);
      let array = value.split("|");
      this.Form.pkCorp = array[0];
      this.Form.pkCorpName = array[1];
    },

    // 库管员列表
    getcwhsmanagerId(data) {
      let array = data.split("|");
      this.Form.cwhsmanagerName = array[1];
      this.Form.cwhsmanagerid = array[2];
      console.log(" this.Form", this.Form);
    },
    // 业务员列表
    getsalesman(data) {
      let array = data.split("|");
      this.Form.salesman = array[2];
      this.Form.salesmanName = array[1];
      this.Form.cbizid = array[2];
      console.log("this.Form.cbizid ", this.Form.cbizid);
      console.log("this.Form.salesman ", this.Form.salesman);
    },

    // 查询人员信息列表
    searchUserInfoList(value) {
      // this.UserList = [];
      if (value != "") {
        let queryPath = "?username=" + value;
        comHttp.getUserInfoByUserName(queryPath).then((res) => {
          for (let i = 0; i < res.result.list.length; i++) {
            if (!this.workNoList.includes(res.result.list[i].workNo)) {
              let data = {
                userName: res.result.list[i].username,
                userId: res.result.list[i].id,
                workNo: res.result.list[i].workNo,
              };
              this.UserList.push(data);
              this.workNoList.push(res.result.list[i].workNo);
            }
          }
        });
      }
    },
    // 获取负责人列表
    getResponsiblePersonList() {
      const roleName = "仓库负责人员";
      let queryPath = "?roleName=" + roleName;
      comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
        // console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            userName: res.result[i].userName,
            userId: res.result[i].userId,
            workNo: res.result[i].workNo,
          };
          this.responsiblePersonList.push(data);
        }
      });
    },
    // 设置负责人id
    setResponsible_person(value) {
      let array = value.split("|");
      this.Form.responsiblePersonName = array[1];
      this.Form.responsiblePerson = array[2];
      console.log("this.Form.responsiblePerson", this.Form.responsiblePerson);
    },
    // 获取审核人
    // getInspectorList() {
    //   const roleName = "仓库审核人员";
    //   let queryPath = "?roleName=" + roleName;
    //   comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
    //     // console.log(res);
    //     for (let i = 0; i < res.result.length; i++) {
    //       let data = {
    //         userName: res.result[i].userName,
    //         userId: res.result[i].userId,
    //         workNo: res.result[i].workNo,
    //       };
    //       this.inspectorList.push(data);
    //       this.inspectorIdList.push(res.result[i].userId);
    //     }
    //   });
    // },

    //入库仓库触发函数
    RuKuCangKuMethod(record) {
      let array = record.split("|");
      this.Form.cotherwhName = array[1];
      this.Form.cotherwhid = array[2];
    },
    //库存组织触发函数
    KuCunZuZhiMethod(record) {
      let array = record.split("|");
      this.Form.pk_calbody = array[0];
      this.Form.bodyname = array[1];
    },
    //----------------------------提示触发组件-测试：开始-----------------------------------
    // tipsSubmit() {
    //   this.tipsvisible = true;
    //   this.tipsDataSource = [
    //     {
    //       key: 1,
    //       depotNo: 1,
    //        depotName: "1",
    //       position: "1",
    //       inventoryNo: "1",
    //       inventoryName: "1",
    //       standardModel: "1",
    //       batchNumber: "1",
    //       balance: "1",
    //       quantity: "1",

    //     },
    //   ];
    // },
    //----------------------------提示触发组件-测试：结束-----------------------------------
    // getParam(){
    //   if(this.$route.path=="InfrastructureOutput"){
    //     this.getRouterParam();
    //   }
    // },
    //延迟
    debounce(value, wait) {
      if (this.timeout) clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        this.onfunc(value);
      }, wait);
    },
    handleSearch(value) {
      this.debounce(value, 2000);
    },
    async onfunc(value) {
      //等待控制
      // this.Waiting = true;
      var goodsList_invname = [];
      var goodsList_invspec = [];
      this.goodsList = [];

      if (value.match(/^[ ]*$/)) {
        console.log("字符串为空或全空格");
      } else {
        this.goodsList = [];
        console.log("value", value);
        let query = "?name=" + value;
        console.log("query", query);
        if (value == "" || value == null) {
          this.goodsList = [];
        } else {
          this.goodsList = [];
          //存货名称模糊查询
          await comHttp
            .getgetSearchInventoryInformationFile(query)
            .then((res) => {
              console.log("结果为", res);
              // this.goodsList = res.result;
              for (let i = 0; i < res.result.length; i++) {
                let data = {
                  inventoryId: res.result[i].pkInvbasdoc, // 存货 id
                  inventoryNo: res.result[i].invcode, //存货编码
                  inventoryName: res.result[i].invname, //存货名称
                  specificationsModel: res.result[i].invspec, //规格型号
                  unit: res.result[i].measname, //单位
                };
                goodsList_invname.push(data);
              }
            });

          let queryInventoryBySpec = "?invspec=" + value;
          //规格型号模糊查询
          await comHttp
            .getqueryInventoryBySpec(queryInventoryBySpec)
            .then((res) => {
              console.log("结果规格型号模糊查询", res);

              goodsList_invspec = res.result.list.map((item) => {
                return {
                  inventoryId: item.pkInvbasdoc,
                  inventoryNo: item.invcode,
                  inventoryName: item.invname,
                  specificationsModel: item.invspec,
                  unit: item.measname,
                };
              });
            });
          //todo 合并去重函数
          await this.mergeArray(goodsList_invname, goodsList_invspec);
          //等待控制
          // this.Waiting = false;
        }
      }
    },
    //todo 合并去重函数
    mergeArray(arr1, arr2) {
      let arrs = [...arr1, ...arr2];

      //根据inventoryId去重
      let map = new Map();
      for (let item of arrs) {
        if (!map.has(item.inventoryId)) {
          map.set(item.inventoryId, item);
        }
      }
      this.goodsList = [...map.values()];
    },
    //存货编码自动填充：存货名称、规格型号、单位
    setCunHuoBianMaFunction(record) {
      let key = record.key;
      console.log("record", record);
      console.log("key", record.key);
      console.log("inventoryNo", record.inventoryNo);

      let array = record.inventoryNo.split("|");
      console.log("array", array);
      if (array[2] == null || array[2] == "null") {
        array[2] = "";
      }
      this.dataSource[key - 1].inventoryNo = array[0];
      this.dataSource[key - 1].inventoryNane = array[1];
      this.dataSource[key - 1].standardModel = array[2];
      this.dataSource[key - 1].unit = array[3];
    },
    // 获取路由参数
    getRouterParam() {
      console.log("查询参数:::", this.$route.query.Id);

      // 通过出入库id 查询出入库信息
      if (typeof this.$route.query.Id == "undefined") {
        console.log("常规跳转");
      } else {
        this.setInitInfo(this.$route.query.Id);
      }
    },
    // // 获取路由参数
    // getRouterParam() {
    //   console.log("查询参数:::", this.$route.query.Id);

    //   // 通过出入库id 查询出入库信息
    //   if (typeof this.$route.query.Id == "undefined") {
    //     console.log("常规跳转");
    //   } else {
    //     this.setInitInfo(this.$route.query.Id);
    //   }
    // },

    // 通过路由跳转，设置初始化信息
    async setInitInfo(id) {
      if (typeof id === "undefined" || id === "") {
        this.InitOriginData();
        // this.getApplyOrder();
      } else {
        if (this.$route.query.isAntiAudit == "已反审核") {
          this.isAntiAudit = true;
        }
        this.UpdateTmp = true;

        comHttp
          .getInOrOutStorageOrderAndGoodsInfoById("?id=" + id)
          .then((res) => {
            console.log("通过Id查询出来的信息::::", res);
            this.otherId = res.result.list[0].otherId; // 表一 Id
            this.Form = {
              id: res.result.list[0].otherId, // 表一 Id
              document: res.result.list[0].document, // 单据号
              documentDate: res.result.list[0].documentDate, // 单据日期
              deptIdName: res.result.list[0].deptId_dictText, // 部门
              deptId: res.result.list[0].deptId, // 部门Id
              // 供应商
              sendReceiveTypeName: res.result.list[0].sendReceiveType_dictText, // 收发类别

              pkCalbody: res.result.list[0].pkCalbody, // 库存组织id
              bodyname: res.result.list[0].pkCalbody_dictText, // 库存组织

              pkCorp: res.result.list[0].pkCorp, // 公司id
              pkCorpName: res.result.list[0].pkCorp_dictText, // 公司

              cwhsmanagerid: res.result.list[0].cwhsmanagerid, // 库管员id
              cwhsmanagerName: res.result.list[0].cwhsmanagerid_dictText, // 库管员

              cbizid: res.result.list[0].cbizid, // 业务员id
              salesmanName: res.result.list[0].cbizid_dictText, // 业务员

              cotherwhid: res.result.list[0].cotherwhid, // 入库仓库id
              cotherwhName: res.result.list[0].cotherwhid_dictText, // 入库仓库

              ccustomerid: res.result.list[0].ccustomerid, // 客户id
              ccustomerName: res.result.list[0].ccustomerid_dictText, // 客户

              farmer: res.result.list[0].farmer, // 农户id
              farmerName: res.result.list[0].farmer_dictText, // 农户

              remark: res.result.list[0].remark, // 备注

              responsiblePerson: res.result.list[0].responsiblePerson, // 负责人id
              responsiblePersonName:
                res.result.list[0].responsiblePerson_dictText, // 负责人

              inspector: res.result.list[0].inspector, // 审核人id
              inspectorName: res.result.list[0].inspector_dictText, // 审核人

              singleProducer: res.result.list[0].singleProducer, // 制单人id
              singleProducerName: res.result.list[0].singleProducer_dictText, // 制单人

              //!这里需要加上拥有的新数据后，返回信息了，才知道渲染什么

              // projectsUnderConstruction_text:
              //   res.result.list[0].projectsUnderConstruction_dictText, // 在建项目name
              // projectsUnderConstruction:
              //   res.result.list[0].projectsUnderConstruction, // 在建项目id
              // responsiblePerson: res.result.list[0].responsiblePerson_dictText, // 负责人
              // responsiblePersonId: res.result.list[0].responsiblePerson,
              // inspector: res.result.list[0].inspector_dictText, // 审核人
              // inspectorId: res.result.list[0].inspector,
              // singleProducer: res.result.list[0].singleProducer_dictText, // 制单人
              // singleProducerId: res.result.list[0].singleProducer, //制单人(传userid)
              balance: "", //验收日期
            };

            let array = [];
            for (let i = 0; i < res.result.list.length; i++) {
              console.log("表格信息:::::", 123);

              let data = {
                key: i + 1,
                id: res.result.list[i].twoId, // 表二 Id
                otherId: res.result.list[i].otherId, // 表一Id
                depotNo: res.result.list[i].storcode, // 仓库编码
                depotName: res.result.list[i].storname, // 仓库名称
                depotLocation: res.result.list[i].depotLocation, // 库位
                // depotLocation: res.result.list[i].depotLocation_dictText, // 库位name
                position: res.result.list[i].position, // 仓位
                // storageUnit: res.result.list[i].storageUnit_dictText, // 所属单位
                // storageUnitId: res.result.list[i].storageUnitId, // 所属单位Id
                inventoryId: res.result.list[i].inventoryId, // 存货Id
                inventoryNo: res.result.list[i].inventoryId_dictText, // 存货编码
                inventoryName: res.result.list[i].invname, // 存货名称
                standardModel: res.result.list[i].invspec, // 规格型号
                unit: res.result.list[i].invtype, // 单位
                auxiliaryUnit: res.result.list[i].auxiliaryUnit_dictText, // 辅助单位
                quantity: Number(res.result.list[i].quantity), // 数量
                sourceNumber: res.result.list[i].sourceNumber, // 源单单号
                batchNumber: res.result.list[i].batchNumber, // 批次号
                deliveryDate: res.result.list[i].deliveryDate, // 入库日期
                // goodsList: this.getGoodSInfo(res.result.list[i].depotId),
                BatchList: [],
                isNew: false,
              };

              // 判断到底是显示辅助单位 还是单位
              if (res.result.list[i].auxiliaryUnit != "") {
                data[`unit`] = "";
              } else {
                data[`unit`] = res.result.list[i].unit;
              }

              // 获取物品列表
              data[`goodsList`] = this.getGoodSInfo(res.result.list[i].depotId);

              if (
                res.result.list[i].position == undefined ||
                res.result.list[i].position == "undefined"
              ) {
                // 批次号列表 异步加载
                this.getBatchNumberList(
                  res.result.list[i].depotId,
                  res.result.list[i].inventoryId
                ).then(async (res) => {
                  this.$set(data, "BatchList", res);
                });
              } else {
                // 批次号列表 异步加载
                this.getBatchNumberList(
                  res.result.list[i].depotId,
                  res.result.list[i].inventoryId,
                  res.result.list[i].position
                ).then(async (res) => {
                  this.$set(data, "BatchList", res);
                });
              }

              // 获取仓位列表 异步加载
              this.getPositionList(res.result.list[i].depotId).then(
                async (res) => {
                  if (res != 1) {
                    let temp_data = await this.disableParent(res);
                    // console.log("獲取的數據:::", temp_data);
                    this.$set(data, "positionList", temp_data);
                  }
                }
              );

              array.push(data);
              // this.DataSource[i].= i;
              // this.DataSource[i].depotNo = ;
              // this.DataSource[i].depotId_dictText =
              //   res.result.list[i].depotId_dictText;

              // this.DataSource[i].remark = res.result.list[i].remark;
            }
            this.DataSource = array;
            console.log("表格信息:::", this.DataSource);
            this.UpdateTmp = false;
          });
      }
    },
    InitOriginData() {
      this.Form = {
        id: "", // id
        document: "", // 单据号
        documentDate: moment().format("YYYY-MM-DD"), // 单据日期
        balance: moment().format("YYYY-MM-DD"),
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", // 仓库Id
        // storageUnit: "", // 所属单位名称
        // storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号
        department: "", // 部门名称
        deptId: "", // 部门id

        sendReceiveType: "", // 收发类别名称
        sendReceiveTypeId: "", // 收发类别Id
        projectsUnderConstruction: "", // 在建项目Id
        projectsUnderConstruction_text: "", // 在建项目name
        responsiblePerson: "", // 负责人名称
        responsiblePersonId: "", // 负责人Id
        inspector: "", // 审核人名称
        inspectorId: "", // 审核人Id
        // balance: null, // 审核日期
        singleProducer: this.$store.state.user.info.username, // 制单人名称
        singleProducerId: this.$store.state.user.info.id, // 制单人Id
      };
      this.DataSource = [];
      this.getApplyOrder(); // 获取单号
    },
    // 提交
    Submit() {
      let data = {
        id: this.Form.id,
        bookkeepingMark: 1,
      };
      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("记账成功");
          this.alreadyRecordTag = false;
        } else {
          this.$message.success("记账失败");
        }
      });
    },
    // 重置所有信息
    ResetAll() {
      this.Form = {
        id: "", // id
        document: "", // 单据号
        documentDate: moment().format("YYYY-MM-DD"), // 单据日期
        balance: moment().format("YYYY-MM-DD"),
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", // 仓库Id
        // storageUnit: "", // 所属单位名称
        // storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号
        department: "", // 部门名称
        deptId: "", // 部门id

        sendReceiveType: "", // 收发类别名称
        sendReceiveTypeId: "", // 收发类别Id
        projectsUnderConstruction: "", // 在建项目Id
        projectsUnderConstruction_text: "", // 在建项目name
        responsiblePerson: "", // 负责人名称
        responsiblePersonId: "", // 负责人Id
        inspector: "", // 审核人名称
        inspectorId: "", // 审核人Id
        // balance: null, // 审核日期
        singleProducer: this.$store.state.user.info.username, // 制单人名称
        singleProducerId: this.$store.state.user.info.id, // 制单人Id
      };
      this.DataSource = [];
    },
    //判断数量、现存数量是否符合要求
    judegShuLiang() {
      let temp = true;
      this.DataSource.forEach((element) => {
        if (element.balance <= element.quantity) {
          this.$message.error("数量不能大于现存数量！");
          temp = false;
        }
      });
      return temp;
    },
    // 新增数据,新增表单数据和物品数据
    addOrderDataAndGoodsData() {
      // let temp = this.judegShuLiang();
      let temp = true;
      if (temp) {
        let depotNoFlag = true; //仓库编码
        // let storageUnitFlag = true; //所属单位
        let inventoryNoFlag = true; //存货编码
        let quantityFlag = true; //数量
        // let batchNumberFlag = true; //  批次号
        let deliveryDateFlag = true; //入库日期
        this.DataSource.forEach((element) => {
          if (element.depotNo == "" || element.depotNo == null) {
            depotNoFlag = false;
          }
          // if (element.storageUnit == "" || element.storageUnit == null) {
          //   storageUnitFlag = false;
          // }
          if (element.inventoryNo == "" || element.inventoryNo == null) {
            inventoryNoFlag = false;
          }
          if (element.quantity == "" || element.quantity == null) {
            quantityFlag = false;
          }
          // if (element.batchNumber == "") {
          //   batchNumberFlag = false;
          // }
          if (element.deliveryDate == "" || element.deliveryDate == null) {
            deliveryDateFlag = false;
          }
        });
        if (
          depotNoFlag &&
          // storageUnitFlag &&
          inventoryNoFlag &&
          quantityFlag &&
          // batchNumberFlag &&
          deliveryDateFlag
        ) {
          this.IsNotEmpty = true;
          console.log("jinru ");
          // 过滤物品编码
          let newData = this.DataSource.filter(
            (item) => item.inventoryNo != ""
          );
          let array = [];
          for (let i = 0; i < newData.length; i++) {
            let data = {
              depotId: newData[i].depotId, //! 仓库编码（库存组织外键）
              // position:newData[i].position,//! 仓位 integer(int32) ,放在data后面
              // storageUnit: newData[i].storageUnit, //! 所属单位（库存组织外键）
              inventoryId: newData[i].inventoryId, //! 存货编码（存货信息档案外键）
              // auxiliaryUnit: newData[i].auxiliaryUnitId, //! 辅助单位id integer(int32),放在data后面
              // quantity: Number(newData[i].quantity), //! 数量 number(double),放在data后面
              // unitPrice: Number(newData[i].unitPrice), //! 单价 number(double),放在data后面
              // money: Number(newData[i].money), //! 金额 number(double),放在data后面
              sourceNumber: newData[i].sourceNumber, //! 源单单号（外键）
              batchNumber: newData[i].batchNumber, //! 批次号
              deliveryDate: moment(newData[i].deliveryDate).format(
                "YYYY-MM-DD"
              ), //! 入库日期

              useTo: newData[i].useTo, //! 用途
              remark: newData[i].remark, //! 备注
              amountOfFruitPicking: newData[i].amountOfFruitPicking, //! 出菇领料金额
              BatchList: [],
            };

            if (newData[i].position != "") {
              data[`position`] = parseInt(newData[i].position); // 仓位
            }
            if (newData[i].auxiliaryUnit != "") {
              data[`auxiliaryUnit`] = parseInt(newData[i].auxiliaryUnit); // 辅助单位
            }
            if (newData[i].quantity != "") {
              data[`quantity`] = Number(newData[i].quantity); // 数量
            }
            if (newData[i].unitPrice != "") {
              data[`unitPrice`] = Number(newData[i].unitPrice); // 单价
            }
            if (newData[i].money != "") {
              data[`money`] = Number(newData[i].money); // 单价
            }

            array.push(data);
          }
          // 单据数据+物品树
          let AllData = {
            auditMark: 2, // 审核标志, 1 已审核,2 未审核
            bookkeepingMark: 2, // 记账标志 , 1 已记账 , 2 未记账
            inOutCategoryIdentification: 12, // 入库、出库类别标识, 1-6 采购入库、产成品入库、销售出库、生产材料出库、基建出库、其他出库、其他入库
            inOutIdentification: 1, // 入库、出库标识，1 入库，2 出库

            document: this.Form.document, // 单据号
            documentDate: moment(this.Form.documentDate).format("YYYY-MM-DD"), // 单据日期
            balance: moment(this.Form.balance).format("YYYY-MM-DD"), // 单据日期
            depotId: this.Form.depotId, //仓库Id
            // storageUnit: this.Form.storageUnit, //所属单位名称
            deptId: this.Form.deptId, //部门id
            // sendReceiveType: parseInt(this.Form.sendReceiveType), //收发类别名称 integer(int32)
            cprojectid: this.Form.cprojectid, //在建项目Id 项目（调用用友项目管理档案）
            pkCalbody: this.Form.pkCalbody, //库存组织名称id
            pkCorp: this.Form.pkCorp, //公司id,前端显示数据库名称
            cwhsmanagerid: this.Form.cwhsmanagerid, //库管员id
            salesman: this.Form.salesman, //业务员id
            cbizid: this.Form.cbizid, //业务员id 这里两个都传,传一样的
            cotherwhid: this.Form.cotherwhid, //入库仓库id
            ccustomerid: this.Form.ccustomerid, //供应商id 这个不用了,用下面的
            farmer: this.Form.farmer, //农户id
            remark: this.Form.remark, //备注
            responsiblePerson: this.Form.responsiblePerson, //负责人 (传userid)）
            inspector: this.Form.inspector, // 审核人(传userid)
            singleProducer: this.Form.singleProducer, //! 制单人(传userid),在保存时有，路由跳转过来的没有
            //balance: this.Form.balance, //! 审核日期,在路由跳转过来时才存储
            warehouseObjectInformationEntities: array,
          };
          if (this.Form.sendReceiveType != "") {
            AllData[`sendReceiveType`] = parseInt(this.Form.sendReceiveType); // 仓位
          }

          console.log("全部的数据", AllData);
          comHttp.addInOrOutStorageOrderAndGoods(AllData).then((res) => {
            console.log("提交的数据", res);
            if (res.success) {
              this.$message.success("提交成功");
            } else {
              this.$message.error("提交失败");
            }
          });
        } else {
          this.IsNotEmpty = false;
          this.$message.error("请把表中信息填写完整");
        }
      }
    },
    // addOrderDataAndGoodsData() {
    //   let temp=this.judegShuLiang();
    //   if(temp){

    //   }
    //   let depotNoFlag = true; //仓库编码
    //   let storageUnitFlag = true; //所属单位
    //   let inventoryNoFlag = true; //存货编码
    //   let quantityFlag = true; //数量
    //   // let batchNumberFlag = true; //批次号
    //   let deliveryDateFlag = true; //出库日期
    //   this.DataSource.forEach((element) => {
    //     if (element.depotNo == "" || element.depotNo == null) {
    //       depotNoFlag = false;
    //     }
    //     if (element.storageUnit == "" || element.storageUnit == null) {
    //       storageUnitFlag = false;
    //     }
    //     if (element.inventoryNo == "" || element.inventoryNo == null) {
    //       inventoryNoFlag = false;
    //     }
    //     if (element.quantity == "" || element.quantity == null) {
    //       quantityFlag = false;
    //     }
    //     // if (element.batchNumber == "") {
    //     //   batchNumberFlag = false;
    //     // }
    //     if (element.deliveryDate == "" || element.deliveryDate == null) {
    //       deliveryDateFlag = false;
    //     }
    //   });
    //   if (
    //     depotNoFlag &&
    //     storageUnitFlag &&
    //     inventoryNoFlag &&
    //     quantityFlag &&
    //     // batchNumberFlag &&
    //     deliveryDateFlag
    //   ) {
    //     console.log("jinru ");
    //     // 过滤物品编码
    //     let newData = this.DataSource.filter((item) => item.inventoryNo != "");
    //     let array = [];
    //     for (let i = 0; i < newData.length; i++) {
    //       let data = {
    //         depotId: newData[i].depotId, // 仓库编码（库存组织外键）
    //         // depotLocation: newData[i].depotLocation, // 库位id
    //         // position: newData[i].position, // 仓位id
    //         storageUnit: parseInt(newData[i].storageUnitId), // 所属单位id
    //         inventoryId: parseInt(newData[i].inventoryId), // 存货编码id
    //         auxiliaryUnit: newData[i].auxiliaryUnitId, // 辅助单位id
    //         quantity: parseInt(newData[i].quantity), // 数量int
    //         sourceNumber: newData[i].sourceNumber, // 源单单号string
    //         batchNumber: newData[i].batchNumber, // 批次号string
    //         BatchList: [],
    //         deliveryDate: moment(newData[i].deliveryDate).format("YYYY-MM-DD"), // 出库日期
    //         // depotLocation: parseInt(newData[i].depotLocation), // 库位
    //         // position: parseInt(newData[i].position), // 仓位
    //         remark: newData[i].remark, // 备注
    //       };
    //       if (newData[i].auxiliaryUnitId != "") {
    //         data[`auxiliaryUnit`] = parseInt(newData[i].auxiliaryUnitId); // 辅助单位
    //       }
    //       if (newData[i].position != "") {
    //         data[`position`] = newData[i].position; // 仓位
    //       }
    //       if (newData[i].depotLocation != "") {
    //         data[`depotLocation`] = newData[i].depotLocation; // 库位
    //       }
    //       if (newData[i].deliveryDate != "") {
    //         data[`deliveryDate`] = newData[i].deliveryDate; // 库位
    //       }

    //       array.push(data);
    //     }
    //     // 单据数据+物品树
    //     let AllData = {
    //       auditMark: 2, // 审核标志, 1 已审核,2 未审核
    //       bookkeepingMark: 2, // 记账标志 , 1 已记账 , 2 未记账
    //       inOutCategoryIdentification: 5, // 入库、出库类别标识, 1-6 采购入库、产成品入库、销售出库、生产材料出库、基建出库、其他出库
    //       inOutIdentification: 2, // 入库、出库标识，1 入库，2 出库
    //       document: this.Form.document, // 单据号
    //       documentDate: moment(this.Form.documentDate).format("YYYY-MM-DD"), // 单据日期
    //       deptId: this.Form.deptId, // 部门
    //       sendReceiveType: parseInt(this.Form.sendReceiveTypeId), // 收发类别
    //       projectsUnderConstruction: parseInt(
    //         this.Form.projectsUnderConstruction
    //       ), // 在建项目
    //       responsiblePerson: this.Form.responsiblePersonId, // 负责人 (传userid)）
    //       inspector: this.Form.inspectorId, // 审核人(传userid)
    //       singleProducer: this.Form.singleProducerId, //! 制单人(传userid),在保存时有，路由跳转过来的没有
    //       //balance: this.Form.balance, //! 审核日期,在路由跳转过来时才存储
    //       warehouseObjectInformationEntities: array,
    //     };

    //     console.log("全部的数据", AllData);
    //     comHttp.addInOrOutStorageOrderAndGoods(AllData).then((res) => {
    //       console.log("提交的数据", res);
    //       if (res.code == 200) {
    //         this.$message.success("提交成功");
    //       } else {
    //         this.$message.error("提交失败");
    //       }
    //     });
    //   } else {
    //     this.$message.error("请把表中信息填写完整");
    //   }
    // },
    // 更新表单和物品数据
    updateOrderAndGoodsData() {
      let temp = this.judegShuLiang();
      if (temp) {
        let depotNoFlag = true; //仓库编码
        // let storageUnitFlag = true; //所属单位
        let inventoryNoFlag = true; //存货编码
        let quantityFlag = true; //数量
        // let batchNumberFlag = true; //批次号
        let deliveryDateFlag = true; //出库日期
        this.DataSource.forEach((element) => {
          if (element.depotNo == "" || element.depotNo == null) {
            depotNoFlag = false;
          }
          // if (element.storageUnit == "" || element.storageUnit == null) {
          //   storageUnitFlag = false;
          // }
          if (element.inventoryNo == "" || element.inventoryNo == null) {
            inventoryNoFlag = false;
          }
          if (element.quantity == "" || element.quantity == null) {
            quantityFlag = false;
          }
          // if (element.batchNumber == "") {
          //   batchNumberFlag = false;
          // }
          if (element.deliveryDate == "" || element.deliveryDate == null) {
            deliveryDateFlag = false;
          }
        });
        if (
          depotNoFlag &&
          // storageUnitFlag &&
          inventoryNoFlag &&
          quantityFlag &&
          // batchNumberFlag &&
          deliveryDateFlag
        ) {
          this.IsNotEmpty = true;
          console.log("进入更新", this.DataSource);
          console.log(this.Form);
          let newData = this.DataSource.filter(
            (item) => item.inventoryNo != ""
          );
          let updateArray = [];
          console.log("数据：：：：：", newData);
          // 物品
          for (let i = 0; i < newData.length; i++) {
            if (newData[i].isNew == false) {
              let data = {
                id: newData[i].id, // 表二Id

                depotId: newData[i].depotId, //! 仓库编码（库存组织外键）
                // position:newData[i].position,//! 仓位 integer(int32) ,放在data后面
                // storageUnit: newData[i].storageUnitId, //! 所属单位（库存组织外键）
                inventoryId: newData[i].inventoryId, //! 存货编码（存货信息档案外键）
                // auxiliaryUnit: newData[i].auxiliaryUnitId, //! 辅助单位id integer(int32),放在data后面
                // quantity: Number(newData[i].quantity), //! 数量 number(double),放在data后面
                // unitPrice: Number(newData[i].unitPrice), //! 单价 number(double),放在data后面
                // money: Number(newData[i].money), //! 金额 number(double),放在data后面
                sourceNumber: newData[i].sourceNumber, //! 源单单号（外键）
                batchNumber: newData[i].batchNumber, //! 批次号
                deliveryDate: moment(newData[i].deliveryDate).format(
                  "YYYY-MM-DD"
                ), //! 出库日期

                useTo: newData[i].useTo, //! 用途
                remark: newData[i].remark, //! 备注
                amountOfFruitPicking: newData[i].amountOfFruitPicking, //! 出菇领料金额
                BatchList: [],
              };
              if (newData[i].position != "") {
                data[`position`] = parseInt(newData[i].position); // 仓位
              }
              if (newData[i].auxiliaryUnit != "") {
                data[`auxiliaryUnit`] = parseInt(newData[i].auxiliaryUnit); // 辅助单位
              }
              if (newData[i].quantity != "") {
                data[`quantity`] = Number(newData[i].quantity); // 数量
              }
              if (newData[i].unitPrice != "") {
                data[`unitPrice`] = Number(newData[i].unitPrice); // 单价
              }
              if (newData[i].money != "") {
                data[`money`] = Number(newData[i].money); // 单价
              }
              updateArray.push(data);
            }
          }
          // 单据
          let data = {
            id: this.Form.id,
            auditMark: 2, // 审核标志, 1 已审核,2 未审核
            bookkeepingMark: 2, // 记账标志 , 1 已记账 , 2 未记账
            inOutCategoryIdentification: 12, // 入库、出库类别标识, 1-6 采购入库、产成品入库、销售出库、生产材料出库、基建出库、其他出库
            inOutIdentification: 2, // 入库、出库标识，1 入库，2 出库

            document: this.Form.document, // 单据号
            documentDate: moment(this.Form.documentDate).format("YYYY-MM-DD"), // 单据日期
            balance: moment(this.Form.balance).format("YYYY-MM-DD"), // 审核日期

            depotId: this.Form.depotId, //仓库Id
            // storageUnit: this.Form.storageUnit, //所属单位名称
            deptId: this.Form.deptId, //部门id
            // sendReceiveType: parseInt(this.Form.sendReceiveType), //收发类别名称 integer(int32)
            cprojectid: this.Form.cprojectid, //在建项目Id 项目（调用用友项目管理档案）
            pkCalbody: this.Form.pkCalbody, //库存组织名称id
            pkCorp: this.Form.pkCorp, //公司id,前端显示数据库名称
            cwhsmanagerid: this.Form.cwhsmanagerid, //库管员id
            salesman: this.Form.salesman, //业务员id
            cbizid: this.Form.cbizid, //业务员id 这里两个都传,传一样的
            cotherwhid: this.Form.cotherwhid, //入库仓库id
            ccustomerid: this.Form.ccustomerid, //供应商id 这个不用了,用下面的
            farmer: this.Form.farmer, //农户id
            remark: this.Form.remark, //备注
            responsiblePerson: this.Form.responsiblePerson, //负责人 (传userid)）
            inspector: this.Form.inspector, // 审核人(传userid)
            singleProducer: this.Form.singleProducer, //! 制单人(传userid),在保存时有，路由跳转过来的没有
            //balance: this.Form.balance, //! 审核日期,在路由跳转过来时才存储
            // document: this.Form.document, // 单据号
            // documentDate: moment(this.Form.documentDate).format("YYYY-MM-DD"), // 单据日期
            // deptId: this.Form.deptId, // 部门
            // sendReceiveType: parseInt(this.Form.sendReceiveType), // 收发类别

            // pkCalbody: this.Form.pkCalbody, //库存组织
            // pkCorp: this.Form.pkCorp, //公司
            // cwhsmanagerid: this.Form.cwhsmanagerid, //库管员
            // salesman: this.Form.salesman, //业务员
            // cotherwhid: this.Form.cotherwhid, //入库仓库
            // clientId: this.Form.clientId, //供应商
            // farmers: this.Form.farmers, //农户
            // remark: this.Form.remark, //备注
            // cprojectid: this.Form.cprojectid, //在建项目
            // projectsUnderConstruction: this.Form.projectsUnderConstruction, //在建项目

            // // projectsUnderConstruction: parseInt(
            // //   this.Form.projectsUnderConstruction
            // // ), // 在建项目

            // responsiblePerson: this.Form.responsiblePersonId, // 负责人 (传userid)）
            // inspector: this.Form.inspectorId, // 审核人(传userid)
            // singleProducer: this.Form.singleProducerId, //! 制单人(传userid),在保存时又，路由跳转过来的没有
            // //balance: this.Form.balance, //! 审核日期,在路由跳转过来时才存储
            warehouseObjectInformationEntities: updateArray,
          };
          if (this.Form.sendReceiveType != "") {
            data[`sendReceiveType`] = parseInt(this.Form.sendReceiveType); // 仓位
          }

          console.log("要更新的数据::::::", data);
          comHttp.updateInOrOutStorageOrderAndGoods(data).then((res) => {
            console.log(res);
          });
        } else {
          this.IsNotEmpty = false;
          this.$message.error("请把表中信息填写完整");
        }
      }
    },
    // 新增物品数据
    addGoodsData() {
      let temp = this.judegShuLiang();
      if (temp) {
        let depotNoFlag = true; //仓库编码
        // let storageUnitFlag = true; //所属单位
        let inventoryNoFlag = true; //存货编码
        let quantityFlag = true; //数量
        // let batchNumberFlag = true; //批次号
        let deliveryDateFlag = true; //出库日期
        this.DataSource.forEach((element) => {
          if (element.depotNo == "" || element.depotNo == null) {
            depotNoFlag = false;
          }
          // if (element.storageUnit == "" || element.storageUnit == null) {
          //   storageUnitFlag = false;
          // }
          if (element.inventoryNo == "" || element.inventoryNo == null) {
            inventoryNoFlag = false;
          }
          if (element.quantity == "" || element.quantity == null) {
            quantityFlag = false;
          }
          // if (element.batchNumber == "") {
          //   batchNumberFlag = false;
          // }
          if (element.deliveryDate == "" || element.deliveryDate == null) {
            deliveryDateFlag = false;
          }
        });
        if (
          depotNoFlag &&
          // storageUnitFlag &&
          inventoryNoFlag &&
          quantityFlag &&
          // batchNumberFlag &&
          deliveryDateFlag
        ) {
          this.IsNotEmpty = true;
          let newData = this.DataSource.filter(
            (item) => item.inventoryNo != ""
          );
          let addArray = [];
          for (let i = 0; i < newData.length; i++) {
            if (newData[i].isNew == true) {
              let data = {
                otherId: this.otherId, // 表一Id

                depotId: newData[i].depotId, //! 仓库编码（库存组织外键）
                // position:newData[i].position,//! 仓位 integer(int32) ,放在data后面
                // storageUnit: newData[i].storageUnitId, //! 所属单位（库存组织外键）
                inventoryId: newData[i].inventoryId, //! 存货编码（存货信息档案外键）
                // auxiliaryUnit: newData[i].auxiliaryUnitId, //! 辅助单位id integer(int32),放在data后面
                // quantity: Number(newData[i].quantity), //! 数量 number(double),放在data后面
                // unitPrice: Number(newData[i].unitPrice), //! 单价 number(double),放在data后面
                // money: Number(newData[i].money), //! 金额 number(double),放在data后面
                sourceNumber: newData[i].sourceNumber, //! 源单单号（外键）
                batchNumber: newData[i].batchNumber, //! 批次号
                deliveryDate: moment(newData[i].deliveryDate).format(
                  "YYYY-MM-DD"
                ), //! 出库日期

                useTo: newData[i].useTo, //! 用途
                remark: newData[i].remark, //! 备注
                amountOfFruitPicking: newData[i].amountOfFruitPicking, //! 出菇领料金额
                BatchList: [],

                // depotId: newData[i].depotId, // 仓库编码
                // depotLocation: newData[i].depotLocation, // 库位
                // position: newData[i].position, // 仓位
                // storageUnit: newData[i].storageUnitId, // 所属单位
                // inventoryId: newData[i].inventoryId, // 存货编码
                // auxiliaryUnit: newData[i].auxiliaryUnitId, // 辅助单位
                // quantity: newData[i].quantity, // 数量
                // sourceNumber: newData[i].sourceNumber, // 源单单号
                // batchNumber: newData[i].batchNumber, // 批次号
                // BatchList: [],

                // // giveaway: newData[i].giveaway, // 是否赠品
                // deliveryDate: newData[i].deliveryDate, // 出库日期
                // // remark: newData[i].remark, // 备注
                // // remark: newData[i].remark, // 在建项目

                // unitPrice: 0, // 单价

                // remark: newData[i].remark, // 备注
              };
              if (newData[i].position != "") {
                data[`position`] = parseInt(newData[i].position); // 仓位
              }
              if (newData[i].auxiliaryUnit != "") {
                data[`auxiliaryUnit`] = parseInt(newData[i].auxiliaryUnit); // 辅助单位
              }
              if (newData[i].quantity != "") {
                data[`quantity`] = Number(newData[i].quantity); // 数量
              }
              if (newData[i].unitPrice != "") {
                data[`unitPrice`] = Number(newData[i].unitPrice); // 单价
              }
              if (newData[i].money != "") {
                data[`money`] = Number(newData[i].money); // 单价
              }
              addArray.push(data);
            }
          }
          // 新增接口
          comHttp.addInOrOutStorageGoods(addArray).then((res) => {
            console.log(res);
          });
        } else {
          this.IsNotEmpty = false;

          this.$message.error("请把表中信息填写完整");
        }
      }
    },
    // 保存
    Save() {
      if (this.Form.document == "") {
        this.$message.error("未获取到单据号,请刷新页面重试");
        return;
      }
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$refs.ruleFormUnder.validate((validunder) => {
            if (validunder) {
              console.log("进入save");

              // 通过更新标志来控制，是否是路由跳转过来的，还是新打开的页面
              // 如果是路由跳转过来的，那就是在原有的基础上进行修改，走修改接口和新增接口，修改物品和新增订单物品
              // 如果不是路由跳转过来的，走新增两个接口，新增订单和新增订单物品
              if (this.UpdateTmp) {
                // 新增数据,新增表单数据和物品数据
                this.addOrderDataAndGoodsData();
                if (this.IsNotEmpty) {
                  this.ResetAll(); //重置数据
                  this.getApplyOrder(); // 获取单号
                  this.setDataSource(); //设置默认显示一行
                }
                // this.ResetAll(); //重置数据
                // this.getApplyOrder(); // 获取单号
                // this.setDataSource(); //设置默认显示一行
              } else {
                this.updateOrderAndGoodsData(); // 更新表单和物品数据
                this.addGoodsData(); // 新增物品数据
                this.$message.success("操作成功！");

                if (this.IsNotEmpty) {
                  this.ResetAll(); //重置数据
                  this.getApplyOrder(); // 获取单号
                }
              }
            } else {
              this.$message.error("请把下方信息填写完整");
            }
          });
        } else {
          console.log("请把头部信息填写完整");
          this.$message.error("请把头部信息填写完整");
        }
      });
    },

    // -------------------- 已经写完的 ::::::::::: --------------------------
    // 格式化出库日期
    formatDeliveryDate(key) {
      let target = this.DataSource.filter((item) => item.key === key)[0];
      target.deliveryDate = moment(target.deliveryDate).format("YYYY-MM-DD");
      console.log("修改好的时间为::::", target.deliveryDate);
    },

    //从子组件中获取选中数据
    // getsource(value){
    //   console.log("value",value);

    // },

    // 获取单号
    getApplyOrder() {
      comHttp.getOrder("?string=" + "QTRK-").then((res) => {
        this.Form.document = res.message;
      });
    },
    // 表格取消一行
    cancle(key) {
      console.log(key);
      if (this.DataSource.length > 1) {
        this.DataSource.splice(key - 1, 1);

        // 对序号进行重新赋值
        for (let i = key - 1; i < this.DataSource.length; i++) {
          this.DataSource[i].key = i + 1;
        }

        this.$message.success("取消成功");
      } else {
        this.$message.error("至少保留一行");
      }
    },
    // 获取仓库
    getApplyStorage() {
      this.storageList = [];
      // 获取仓库名称
      comHttp.getStorageName().then((res) => {
        // console.log("获取所有仓库", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            depotName: res.result[i].storname, //仓库名称
            depotNo: res.result[i].storcode, //仓库编码
            depotId: res.result[i].pkStordoc, //id
          };
          this.storageList.push(data);
        }
        console.log("this.storageList", this.storageList);
      });
    },
    // 表格选择事件,
    onSelectChange(selectedRowKeys) {
      console.log("selectedRowKeys changed: ", selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys;
    },
    // 获取物品信息,后期可能会修改为根据仓库id获取物品信息，因为物品信息是根据仓库id来的！！！！！
    getGoodSInfo(id) {
      let goodsList = [];
      comHttp.getInventoryInformationByStorageId("?id=" + id).then((res) => {
        // console.log("获取存货信息:::::", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            inventoryId: res.result[i].id, // 存货 id
            inventoryName: res.result[i].inventoryName,
            inventoryNo: res.result[i].inventoryNo,
            standardModel: res.result[i].specificationsModel,
            unit: res.result[i].unit,
          };
          goodsList.push(data);
        }
        console.log(goodsList);
      });
      return goodsList;
    },
    // 表单仓库点击按钮 -------- 上方选择仓库后，下方物品都填入该仓库
    setdataSourceDepartment(value, option) {
      let array = value.split("|");
      console.log(array[0]);
      let key = option.key;
      // 获取物品信息列表,根据仓库编码
      let goodsList = this.getGoodSInfo(key);
      // let TempList = this.setGoodsList(key);
      // console.log("let TempList", TempList);
      // option.key
      // 根据仓库查询物品信息,并存储到相应的物品信息表中
      for (let i = 0; i < this.DataSource.length; i++) {
        this.DataSource[i].depotNo = array[0];
        this.DataSource[i].depotName = array[1];
        // this.DataSource[i].depotId = array[2];
        this.DataSource[i].depotId = key;

        this.DataSource[i].goodsList = goodsList;

        // this.DataSource[i].goodsList = goodsList;
        // this.DataSource[i].positionList = TempList;
        console.log("for循环中的数据", this.DataSource);
      }
      console.log("赋值好的表格内容:::::", this.DataSource);
    },
    // 获取存货信息
    async getInventoryInfo(record) {
      console.log("record11111111111111111111111111", record);
      let key = record.key;
      let target = this.DataSource.filter((item) => item.key === key)[0];
      console.log("target", target);
      // 分割字符串,取出来存货编码
      let array = target.inventoryName.split("|");
      console.log("array", array);
      target.inventoryId = array[0];
      target.inventoryNo = array[1]; // 赋值给存货编码
      target.inventoryName = array[2]; // 赋值给存货名称
      if (array[3] != "null") {
        target.standardModel = array[3]; // 赋值给规格型号
      } else {
        target.standardModel = "";
      }

      if (array[4] != "null") {
        target.unit = array[4]; // 赋值给单位
      } else {
        target.unit = ""; // 赋值给单位
      }

      // console.log("目标物品信息:::::",target.goodsList)

      // 递归查询出来物品信息
      // let goodsInfomation = [];
      // for (let i = 0; i < this.goodsList.length; i++) {
      //   if (this.goodsList[i].inventoryNo == array[0]) {
      //     goodsInfomation = this.goodsList[i];
      //   }
      // }
      // console.log("物品信息::::", goodsInfomation);
      // target.standardModel = goodsInfomation.standardModel;
      // target.unit = goodsInfomation.unit;
      target.auxiliaryUnit = ""; // 重置辅助单位
      target.auxiliaryUnitId = ""; // 重置辅助单位
      target.giveawayId = 2; //

      // target.BatchList = await this.getBatchNumberList(
      //   target.depotId,
      //   goodsInfomation.inventoryId
      // ); // 获取批次列表
      console.log(" target.position", target.position);
      if (target.position == undefined || target.position == "undefined") {
        target.BatchList = await this.getBatchNumberList(
          target.depotId,
          target.inventoryId
        );
      } else {
        target.BatchList = await this.getBatchNumberList(
          target.depotId,
          target.inventoryId,
          target.position
        );
      }

      // console.log("批次号列表::::", target.BatchList);
      console.log("批次号列表::::", target.BatchList);
      //获取现存总数量
      // target.balance = await this.getBalanceTemp(
      //   // target.depotId, //仓库Id
      //   // target.inventoryId //存货 id
      //   record
      // );
    },
    //————————————————————上方表单的仓库，生成表格中的库位仓位下拉框：开始——————————————————
    getKuWeiList(id) {
      console.log("进入getKuWeiList");
      comHttp.getPositionInformationListByDepotId("?id=" + id).then((res) => {
        this.positionList = res.result[0].children;
        console.log("res", res);
      });
    },

    //————————————————————上方表单的仓库，生成表格中的库位仓位下拉框：结束——————————————————
    // 设置存货列表
    async setGoodsList(key) {
      console.log("进入异步！！！！！！！！！！！");
      let target = this.DataSource.filter((item) => item.key === key)[0];
      let array = target.depotNo.split("|");
      target.depotNo = array[0]; // 仓库id
      target.depotName = array[1]; // 仓库名称

      let SotrageInfo = this.storageList.filter(
        (item) => item.depotNo === array[0]
      )[0];
      target.depotId = SotrageInfo.depotId;
      // let goodsList = this.getGoodSInfo(target.depotId);
      // target.goodsList = goodsList;

      let positionList = await this.getPositionList(target.depotId);
      console.log("positionList", positionList);

      let TempList = await this.disableParent(positionList);
      console.log("仓位列表111", TempList);
      target.positionList = TempList;
      // return TempList;
      //获取现存总数量
      // target.balance = await this.getBalanceTemp(
      //   // target.depotId, //仓库Id
      //   // target.inventoryId //存货 id
      //   target
      // );
    },
    // 选择辅助单位后,单位置空
    disableUnit(key) {
      let target = this.DataSource.filter((item) => item.key === key)[0];

      let array = target.auxiliaryUnit.split("|");
      target.auxiliaryUnit = array[0];
      target.auxiliaryUnitId = array[1];
      console.log("选择辅助单位的记录", target);

      if (target.inventoryNo == "") {
        this.$message.error("请先选择存货信息");
        target.auxiliaryUnit = "";
        target.auxiliaryUnitId = "";
      } else {
        target.unit = "";
      }
    },
    // 获取辅助单位
    getAuxiliary_Unitlist() {
      comHttp.getAuxiliaryUnit().then((res) => {
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            title: res.result[i].title,
            value: res.result[i].value,
          };
          this.Auxiliary_Unitlist.push(data);
        }
        // console.log("获取辅助单位列表::::",  this.Auxiliary_Unitlist);
      });
    },
    // 设置所属单位, 上面表单触发事件
    // setdataSourcestorageUnit(value) {
    //   let array = value.split("|");
    //   this.Form.storageUnit = array[2];
    //   this.Form.storageUnitName = array[1];
    //   console.log("this.Form.storageUnitName", this.Form.storageUnitName);
    //   // console.log(array[0]);
    //   // let key = option.key;
    //   // option.key
    //   // 根据仓库查询物品信息,并存储到相应的物品信息表中
    //   for (let i = 0; i < this.DataSource.length; i++) {
    //     this.$set(this.DataSource[i], "storageUnitName", array[1]);
    //     this.$set(this.DataSource[i], "storageUnit", array[2]);
    //     // this.DataSource[i].storageUnitName = array[1];
    //     // this.DataSource[i].storageUnit = array[2];//id
    //     // this.DataSource[i].storageUnitId = key;
    //   }
    //   console.log(
    //     "this.DataSource.storageUnit",
    //     this.DataSource[0].storageUnit
    //   );
    //   console.log(
    //     "this.DataSource.storageUnitName",
    //     this.DataSource[0].storageUnitName
    //   );
    // },
    // 获取所属单位,表格触发事件
    // getstorageUnitId(value, record) {
    //   let array = value.split("|");
    //   record.storageUnitName = array[1]; // 仓库name
    //   record.storageUnit = array[2]; // 仓库id
    // },
    //单据日期触发函数
    onChange(date, dateString) {
      console.log("date", date);
      console.log("dateString", dateString);
      this.Form.documentDate = dateString;
      this.Form.balance = dateString;
      this.DataSource.forEach((item, index) => {
        this.DataSource[index].deliveryDate = dateString;
      });
    },
    // 获取部门列表
    getDeparmentTree() {
      // console.log("获取部门列表hanshu===");
      comHttp.getDepartmentTreeNew().then((res) => {
        if (res.success) {
          console.log("获取部门树", res);
          this.depTree = res.result;

          this.getYongYou(this.depTree);
          // console.log("this.depTree", this.depTree);
        }
      });
    },
    //将用友中采购部门的格式转换成Tree识别的格式
    getYongYou(tree) {
      tree.forEach((element) => {
        element["title"] = element.deptcode + " " + element.deptname;
        element["value"] = element.pkDeptdoc + "|" + element.deptname;
        element["children"] = element.syncDepartmentFilesEntityList;
        element["key"] = element.id;

        if (element.children) {
          this.getYongYou(element.children);
        }
      });
    },
    // // 获取部门列表
    // getDeparmentTree() {
    //   // console.log("获取部门列表hanshu===");
    //   comHttp.getDepartmentList().then((res) => {
    //     if (res.success) {
    //       let resetRes = res.result;
    //       this.resetDepartmentTree(resetRes);
    //       this.depTree = resetRes;
    //     }
    //   });
    // },
    // // 部门字典表中每一项vlaue 变成 title 为了方便搜索
    // resetDepartmentTree(dep) {
    //   dep.forEach((item) => {
    //     item.value = item.title;
    //     let temp = {
    //       value: item.value,
    //       id: item.id,
    //     };
    //     this.buMenList.push(temp);
    //     if (item.children) {
    //       this.resetDepartmentTree(item.children);
    //     }
    //   });
    // },
    // 部门下拉框选择
    //根据提交部门的title，找到对应value,并给部门id赋值
    onChangeBumen(a) {
      console.log("a", a);
      let array = a.split("|");
      this.Form.deptId = array[0];
      this.Form.deptIdName = array[1];
    },
    //  onChangeBumen(value, b, c, d) {
    //     console.log("value", value);
    //     console.log("b", b);
    //     console.log("c", c);
    //     console.log("d", d);
    //     console.log("this.form", this.form);
    //     // this.form.bumen = [];
    //     // this.form.bumen = value;
    //     for (let i = 0; i < this.buMenList.length; i++) {
    //       if (value == this.buMenList[i].value) {
    //         this.Form.deptId = this.buMenList[i].id; //申请部门id
    //         this.Form.department = this.buMenList[i].value; //申请部门名称

    //         break;
    //       }
    //     }
    //     console.log("1111111111", this.form);

    //   },

    // 获取销售部门列表
    getSaleDepartmentList() {
      this.saleDepartmentList = [];
      comHttp.getSaleDepartment().then((res) => {
        // console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            value: res.result[i].value,
            title: res.result[i].title,
          };
          this.saleDepartmentList.push(data);
        }
      });
    },
    // 获取负责人列表
    // getResponsiblePersonList() {
    //   console.log("进入负责人列表！！！！");
    //   const roleName = "仓库负责人员";
    //   let queryPath = "?roleName=" + roleName;
    //   comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
    //     // console.log(res);
    //     for (let i = 0; i < res.result.length; i++) {
    //       let data = {
    //         userName: res.result[i].userName,
    //         userId: res.result[i].userId,
    //         workNo: res.result[i].workNo,
    //       };
    //       this.responsiblePersonList.push(data);
    //     }
    //   });
    // },
    // // 设置负责人id
    // setResponsible_person(value, options) {
    //   let array = value.split("|");
    //   this.Form.responsiblePerson = array[1];
    //   this.Form.responsiblePersonId = options.key;
    // },
    // 获取审核人
    getInspectorList() {
      console.log("获取审核人");
      const roleName = "仓库审核人员";
      let queryPath = "?roleName=" + roleName;
      comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
        console.log("仓库审核人员res", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            userName: res.result[i].userName,
            userId: res.result[i].userId,
            workNo: res.result[i].workNo,
          };
          this.inspectorList.push(data);
          this.inspectorIdList.push(res.result[i].userId);
        }
      });
    },
    // 设置审核人id
    setInspector(value, options) {
      console.log(options);
      let array = value.split("|");
      this.Form.inspector = array[0];
      this.Form.inspectorName = array[2];
    },
    // // 获取批次号
    // getBatchNumberList(target,id1, id2) {
    //   console.log(id1, id2);
    //   let temp = [];
    //   comHttp
    //     .getgetBatchNumberById("?depotId=" + id1 + "&inventoryId=" + id2)
    //     .then((res) => {
    //       console.log("获取批次号res", res);
    //       temp = res.result;
    //       target.BatchList = temp;

    //     });
    //   return temp;
    // },
    // 获取批次号
    getBatchNumberList(id1, id2, id3 = "") {
      console.log("测试进度44444444444444");

      let temp = [];
      return new Promise((resolve) => {
        comHttp
          .getgetBatchNumberById(
            "?depotId=" + id1 + "&inventoryId=" + id2 + "&position=" + id3
          )
          .then((res) => {
            temp = res.result;
            resolve(temp);
          });
      });
    },

    // 获取全部的仓位信息
    getPositionInformationList() {
      comHttp.getPositionInformationList().then((res) => {
        console.log("仓位信息:::::", res);
      });
    },
    // 删除
    Delete(id) {
      comHttp.deleteInOrOutStorageGoods("?id=" + id).then((res) => {
        if (res && res.code === 200) {
          this.$message.success("删除成功");
        } else {
          this.$message.error("删除失败");
        }
      });
    },

    // 默认设置五行，让用户方便添加
    setDataSource() {
      let size = 1;
      this.DataSource = [];
      for (let i = 0; i < size; i++) {
        let data = {
          key: i + 1,
          isNew: true,
          depotId: "", // 仓库id
          depotNo: "", // 仓库编码
          depotIdName: "", // 仓库编码

          depotName: "", // 仓库名称
          depotLocation: "", // 库位

          position: "", // 仓位

          // storageUnit: "", // 所属单位名称
          // storageUnitId: "", // 所属单位id
          inventoryId: "", // 存货id
          inventoryNo: "", // 存货编码
          inventoryName: "", //  存货名称
          standardModel: "", // , 规格型号
          unit: "", // 单位
          auxiliaryUnit: "", // 辅助单位
          quantity: "", // 	数量
          unitPrice: "", // 单价
          money: "", // 金额
          sourceNumber: "", // 源单单号（外键）
          batchNumber: "", // 批次号

          deliveryDate: moment().format("YYYY-MM-DD"), // 出库日期
          goodsList: [], // 物品信息列
          BatchList: [], // 批次列表
          positionList: [], // 仓位列表
          batchNumberList: [], // 批次号
        };
        this.DataSource.push(data);
      }
    },

    // 表格添加新的一条记录
    newMember() {
      this.DataSource.push({
        key: this.DataSource.length + 1,
        isNew: true,
        depotId: "", // 仓库Id
        depotNo: "", // 仓库编码
        depotName: "", // 仓库名称
        depotLocation: "", // 库位

        position: "", // 仓位

        // storageUnit: "", // 所属单位名称
        // storageUnitId: "", // 所属单位Id
        inventoryId: "", // 存货Id
        inventoryNo: "", // 存货编码
        inventoryName: "", //  存货名称
        standardModel: "", // , 规格型号
        unit: "", // 单位
        auxiliaryUnit: "", // 辅助单位
        auxiliaryUnitId: "", // 辅助单位Id
        balance: "", // 	现存数量
        quantity: "", // 	数量
        unitPrice: "", // 单价
        money: "", // 金额
        sourceNumber: "", // 源单单号（外键）
        batchNumber: "", // 批次号

        // giveaway: "", // 是否赠品
        deliveryDate: moment().format("YYYY-MM-DD"), // 出库日期
        remark: "", // 备注
        goodsList: [], // 物品信息列
        BatchList: [], // 批次列表
        positionList: [], // 仓位列表
        batchNumberList: [], // 批次号
      });
    },
    //收发类别列表
    shoufaleibieListmethod(queryPath = "") {
      console.log("hfougdiuy");
      comHttp.getReceiveSendTypeListAll(queryPath).then((res) => {
        console.log("收发类别列表", res);
        this.shoufaleibieList = res.result.filter(item=>item.receiveFlag===0);
      });
    },
    // 获取收发类别列表
    getSendReceiveList() {
      this.SendReceiveList = [];
      comHttp.getReceiveSendTypeListAll("").then((res) => {
        console.log("收发类别列表:::::", res);
        for (let i = 0; i < res.result.records.length; i++) {
          let data = {
            value: res.result.records[i].id,
            title: res.result.records[i].name,
          };
          this.SendReceiveList.push(data);
        }
      });
    },

    //收发类别触发函数
    shoufaleibieMethod(value) {
      console.log("收发类别触发函数value", value);
      let array = value.split("|");
      console.log("array", array);
      // 表格自动填充所属单位
      this.Form.sendReceiveType = array[0]; //收发类别id
      this.Form.sendReceiveTypeName = array[1]; //收发类别name
    },
    // 获取收发类别Id
    // getSendReceiveTypeId(value, options) {
    //   this.Form.sendReceiveTypeId = options.key;
    // },
    //获取在建项目列表
    // getZaiJianList() {
    //   JiJianChuKu.getZaiJian().then((res) => {
    //     console.log("在建项目", res);
    //     this.zaijianList = res.result.list;
    //   });
    // },
    //在建项目触发函数
    // zaijianMethod(value) {
    //   console.log("在建项目触发函数value", value);
    //   let array = value.split("|");
    //   this.Form.projectsUnderConstruction = parseInt(array[0]);
    //   this.Form.cprojectid = parseInt(array[0]);
    //   this.Form.projectsUnderConstruction_text = array[1];
    //   console.log("在建项目触发函数this.Form", this.Form);
    // },

    // 根据源单生成——获取源单数据
    async getOriginData(data) {
      this.UpdateTmp = true;

      this.DataSource = [];

      console.log("子组件传过来的数据data", data);
      //仓库编码为空的无效数据清空
      let newData = this.DataSource.filter((item) => item.depotNo != "");
      this.DataSource = [];
      this.DataSource = newData;

      console.log("传来的数据data", data);
      let lengthTemp = this.DataSource.length + 1;
      console.log("获取源单数据出发后，显示目前数据的长度+1", lengthTemp);
      //渲染部门、在建项目
      this.Form.deptId = data[0].applicationDept;
      this.Form.deptIdName = data[0].applicationDept_dictText;
      this.Form.projectsUnderConstruction = data[0].projectsUnderConstruction;
      this.Form.cprojectid = data[0].projectsUnderConstruction;
      this.Form.projectsUnderConstruction_text =
        data[0].projectsUnderConstruction_text;

      for (let i = 0; i < data.length; i++) {
        let data1 = {
          key: lengthTemp,
          depotNo: data[i].depotNo, //仓库编码
          depotId: data[i].depotId, //仓库id
          depotName: data[i].depotId_dictText, //仓库名称
          // storageUnitName: data[i].storageUnit_dictText, //所属单位name
          // storageUnit: data[i].storageUnit, //所属单位id
          inventoryId: data[i].inventoryId,
          BatchList: [],

          inventoryNo: data[i].inventoryNo, //存货编码
          inventoryName: data[i].inventoryName,
          standardModel: data[i].standardModel, //规格型号
          unit: data[i].unit, //单位
          quantity: data[i].actualQuantity, //数量
          sourceNumber: data[i].sourceNumber, //源单单号
          applicationDept: data[i].applicationDept, //部门id
          applicationDept_text: data[i].applicationDept_text, //部门name

          // inventoryNo:data[i].inventoryNo
        };
        // data1.goodsList = this.getGoodSInfo(data1.depotId);
        // 获取仓位、库位列表
        console.log("11111111111111111111111111111111111111111");
        let positionList = await this.getPositionList(data1.depotId);
        console.log("2222222222222222222222222222222222222222");
        console.log("获取库位仓位", positionList);
        if (positionList != 1) {
          console.log("测试进度11111111");

          let TempList = await this.disableParent(positionList);
          data1.positionList = TempList;
          console.log("测试进度22222222222");
        }
        console.log("测试进度33333333333333");
        if (data1.position == undefined || data1.position == "undefined") {
          // 获取批次号列表
          data1.BatchList = await this.getBatchNumberList(
            data1.depotId,
            data1.inventoryId
          );
        } else {
          // 获取批次号列表
          data1.BatchList = await this.getBatchNumberList(
            data1.depotId,
            data1.inventoryId,
            data1.position
          );
        }

        // 获取批次号列表
        data1.BatchList = await this.getBatchNumberList(
          data1.depotId,
          data1.inventoryId,
          data1.position
        );
        //获取现存总数量
        data1.balance = await this.getBalanceTempYuanDan(
          // data1.depotId, //仓库Id
          // data1.inventoryId //存货 id
          data[i]
        );
        console.log("测试进度55555555555");

        // let temp = data1.depotId;
        // this.positionList = []; //清空仓位库位下拉框
        // this.getKuWeiList(temp);
        // console.log("this.positionList", this.positionList);
        // data1.positionList = this.positionList;

        data1.deliveryDate = moment().format("YYYY-MM-DD");
        this.DataSource.push(data1);
        console.log("this.DataSource内", this.DataSource);
        lengthTemp++; //序号
      }
      console.log("this.DataSource外", this.DataSource);
    },
    // 禁用父节点
    disableParent(Tree) {
      return new Promise((resolve) => {
        if (Tree != null) {
          Tree.forEach((item) => {
            console.log(item);
            if (item.children.length != 0) {
              item[`disabled`] = true;
            } else {
              this.disableParent(item.children);
            }
          });
        }
        resolve(Tree);
      });
    },
    // 获取仓位列表
    getPositionList(id) {
      console.log(id);
      let positionList = [];
      return new Promise((resolve) => {
        comHttp.getPositionInformationListByDepotId("?id=" + id).then((res) => {
          if (res.result.length != 0) {
            positionList = res.result[0].children;
            resolve(positionList);
          } else {
            resolve(positionList);
          }
        });
      });
    },
    //获取现存总数量
    getBalanceTemp(record) {
      console.log("record", record);
      let data = {
        batchNumber: record.batchNumber,
        depotId: record.depotId,
        inventoryId: record.inventoryId,
        position: record.position,
      };

      // let queryPath =
      //   "?batchNumber=" +
      //   record.batchNumber +
      //   "&depotId=" +
      //   record.depotId +
      //   +"&inventoryId=" +
      //   record.inventoryId +
      //   +"&position=" +
      //   record.position;

      let temp = 0;
      JiJianChuKu.getTotalGoods(data).then((res) => {
        console.log("货物返回值res", res);
        temp = res.result.balance;
        // record.balance = temp; //给本条数据赋值
        this.$set(record, "balance", temp);
        console.log("record22222222222222222", record);

        return Promise.resolve(temp);
      });
    },
    //获取现存总数量---根据源单生成
    getBalanceTempYuanDan(record) {
      console.log("record", record);
      let data = {
        inventoryNo: record.inventoryNo,
        inventoryId: record.inventoryId,
        sourceNumber: "",
      };

      let temp = 0;
      comHttp.getEnableOutOther(data).then((res) => {
        console.log("货物返回值res", res);
        temp = res.result.balance;
        // record.balance = temp; //给本条数据赋值
        this.$set(record, "balance", temp);
        console.log("record22222222222222222", record);

        return Promise.resolve(temp);
      });
    },

    // // 获取仓位列表
    // getPositionList(id) {
    //   let positionList = [];
    //   return new Promise((resolve) => {
    //     comHttp.getPositionInformationListByDepotId("?id=" + id).then((res) => {
    //       console.log(res);
    //       if (res.result.length != 0) {
    //         positionList = res.result[0].children;
    //         resolve(positionList);
    //       } else {
    //         let falseTag = 1;
    //         resolve(falseTag);
    //       }
    //     });
    //   });
    // },
  },
};
</script>

<style></style>
